package h0909;
/**
  * @description 最长公共前缀
  * @author 不知名帅哥
  * @date 2024/9/9 21:29
  * @version 1.0
*/
public class LongestCommonPrefix {
    public static void main(String[] args) {

    }
    public String longestCommonPrefix(String[] strs) {
        String prefix=strs[0];

        for (int i = 1; i < strs.length; i++) {
            while (!strs[i].startsWith(prefix)){
                prefix=prefix.substring(0,prefix.length()-1);
            }
        }
        return prefix;
    }
}
